using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

// 读取路径，用金币展示结果

public class ShowPath : MonoBehaviour
{
    // Start is called before the first frame update
    public Button btn;
    public GameObject path;
    public GameObject coin;
    private double[][] res;
    private int index;
    private string filepath = @"C:\Users\caomb\Desktop\实训\测试路径.txt";
    void Start()
    {
        btn.onClick.AddListener(foo);

        res = new double[300][];
        index = 0;
        // FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
        StreamReader sr = new StreamReader(filepath, Encoding.UTF8);
        string line;
        string[] tmp;
        while(sr.Peek() >= 0){
            line = sr.ReadLine();
            if(line.Length > 0){
                tmp = line.Split();
                res[index] = new double[2];
                res[index][0] = Convert.ToDouble(tmp[0]);
                res[index][1] = Convert.ToDouble(tmp[1]);
                index ++;
            }
        }
        sr.Close();
    }

    // Update is called once per frame
    void foo(){
        Debug.Log("onclick: show the path");

        // GameObject instance = Instantiate(coin, path.transform);
        // instance.transform.localPosition = new Vector3(1,0,0);

        for(int i = 0;i < index;i ++){
            GameObject instance = Instantiate(coin, path.transform);
            instance.transform.localPosition = new Vector3((float)res[i][0], (float)res[i][1],0);
        }
    }
}
